package ${package.Controller};

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import ${package.Entity}.${entity};
import ${superServiceClassPackage};
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
* ${table.comment!}
*
* @author ${author}
* @date ${date}
*/
@RestController
@RequestMapping("/${pathName}")
public class ${className}Controller {

private final  ${className}Service ${classname}Service;

/**
* 简单分页查询
* @param page 分页对象
* @param ${classname} ${comments}
* @return
*/
@ApiOperation(value = "获取对象", notes = "作者：${author}")
@GetMapping("/page")
public R<IPage<${className}>> get${className}Page(Page<${className}> page, ${className} ${classname}) {
return  new R<>(${classname}Service.get${className}Page(page,${classname}));
}


/**
* 通过id查询单条记录
* @param ${pk.lowerAttrName}
* @return R
*/
@ApiOperation(value = "通过id查询单条记录", notes = "作者：${author}")
@ApiImplicitParam(paramType="path", name = "${pk.attrType}", value = "对象id", required = true, dataType = "${pk.attrType}")
@GetMapping("/{${pk.lowerAttrName}}")
public R<${className}> getById(@PathVariable("${pk.lowerAttrName}") ${idType} ${pk.lowerAttrName}){
return new R<>(${classname}Service.getById(${pk.lowerAttrName}));
}

/**
* 新增记录
* @param ${classname}
* @return R
*/
@SysLog("新增${comments}")
@PostMapping
@PreAuthorize("@pms.hasPermission('${moduleName}_${pathName}_add')")
public R save(@RequestBody ${className} ${classname}){
return new R<>(${classname}Service.save(${classname}));
}

/**
* 修改记录
* @param ${classname}
* @return R
*/
@SysLog("修改${comments}")
@PutMapping
@PreAuthorize("@pms.hasPermission('${moduleName}_${pathName}_edit')")
public R update(@RequestBody ${className} ${classname}){
return new R<>(${classname}Service.updateById(${classname}));
}

/**
* 通过id删除一条记录
* @param ${pk.lowerAttrName}
* @return R
*/
@SysLog("删除${comments}")
@DeleteMapping("/{${pk.lowerAttrName}}")
@PreAuthorize("@pms.hasPermission('${moduleName}_${pathName}_del')")
public R removeById(@PathVariable ${pk.attrType} ${pk.lowerAttrName}){
return new R<>(${classname}Service.removeById(${pk.lowerAttrName}));
}

}